package com.TeamJigsaw.DanteTrail.Presenters;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import com.TeamJigsaw.DanteTrail.Models.Checkpoint;
import com.TeamJigsaw.DanteTrail.Models.Party;
import com.TeamJigsaw.DanteTrail.Views.MainViewFrame;
import com.TeamJigsaw.DanteTrail.Views.MapScreenDisplay;
import com.TeamJigsaw.DanteTrail.Views.Interfaces.MapViewInterface;

public class MapViewController implements ViewController{

	private Party party;
	private MainViewFrame mainView;
	private MapViewInterface map;
	private List<Checkpoint> checkpoint;;
	private MapScreenDisplay mapScreen;
	private static boolean first = false;
	
	public MapViewController (Party party, MainViewFrame mainView, List<Checkpoint> cp, Checkpoint prev, String date){
		this.party = party;
		this.mainView = mainView;
		this.checkpoint = cp;
		this.map = this.mainView.getMapView();
				
		map.setNextCheckpoint(checkpoint.get(0).toString());
		map.setPrevCheckpoint(prev.toString());
		map.setDistanceLeft(1909 - this.party.getTotalDistance());
		map.setDistanceToNextCheckpoint(checkpoint.get(0).getLocation()-party.getTotalDistance());
		map.setDistanceTravelled(this.party.getTotalDistance());
		map.setDate(date);
		if(first == false){
			mapScreen = new MapScreenDisplay(party.getPlayer().getPicture(), party.getTotalDistance(), checkpoint);
			map.setMapDisplay(mapScreen);
			first = true;
		}
		
		createListeners();
	}
	
	@Override
	public String toString(){
		return "This is the Map View Controller";
	}

	@Override
	public void createListeners() {
		ActionListener backListener = new BackListener();
		map.setReturnListener(backListener);
	}
	
	private class BackListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			GameViewController gvc = new GameViewController (party, mainView);
			((CardLayout) mainView.getContentPane().getLayout()).show(mainView.getContentPane(), "Game");
			mainView.setTitle("Trail");
		}
		
	}
	
}
